package com.firebird.app.fekpsl.ui.activity.me

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.firebird.app.fekpsl.R
import com.firebird.app.fekpsl.base.BaseMvpActivity
import com.firebird.app.fekpsl.constant.Constant
import com.firebird.app.fekpsl.mvp.me.IsExplicitContract
import com.firebird.app.fekpsl.mvp.me.IsExplicitPresenter
import com.firebird.app.fekpsl.mvp.me.SexContract
import com.firebird.app.fekpsl.mvp.me.SexPresenter
import com.firebird.app.fekpsl.utils.Preference
import kotlinx.android.synthetic.main.me_update_is_explicit.*
import kotlinx.android.synthetic.main.me_update_sex.*
import kotlinx.android.synthetic.main.me_update_sex.btn_save
import kotlinx.android.synthetic.main.toolbar.*

class UpdateIsExplicitActivity  : BaseMvpActivity<IsExplicitContract.View, IsExplicitContract.Presenter>(), IsExplicitContract.View {

    private var pf_is_explicit:Int by Preference(Constant.IS_EXPLICIT_KEY, 1)
    private var pf_uuid:String by Preference(Constant.UUID_KEY, "")
    /**
     * 外显昵称  昵称（1），真名（2）
     */
    private var mIsExplicit = 1

    override fun createPresenter(): IsExplicitContract.Presenter = IsExplicitPresenter()

    private val mDialog by lazy {
        // DialogUtil.getWaitDialog(this, getString(R.string.save_ing))
    }

    override fun showLoading() {
        // mDialog.show()
    }

    override fun hideLoading() {
        // mDialog.dismiss()
    }

    override fun updateIsExplicitSuccess(success: Boolean) {
        if(success){
            pf_is_explicit=mIsExplicit
            finish()
        }else{
            // showToast(getString(R.string.me_save_fail))
        }
    }
    override fun attachLayoutRes(): Int = R.layout.me_update_is_explicit

    override fun initData() {
    }

    override fun initView() {
        super.initView()

        toolbar.run {
            title = resources.getString(R.string.me_explicit_nice_name)
            setSupportActionBar(this)
            supportActionBar?.setDisplayHomeAsUpEnabled(true)
        }

        if (pf_is_explicit == 1) {
            rb_nice_name.isChecked = true
            rb_real_name.isChecked = false
        } else{
            rb_nice_name.isChecked = false
            rb_real_name.isChecked = true
        }

        btn_save.setOnClickListener(onClickListener)

        rg_is_explicit.setOnCheckedChangeListener { group, checkedId ->
            if (checkedId == R.id.rb_nice_name) {
                mIsExplicit = 1
                rb_nice_name.isChecked = true
                rb_real_name.isChecked = false
            } else if (checkedId == R.id.rb_real_name) {
                mIsExplicit = 2
                rb_nice_name.isChecked = false
                rb_real_name.isChecked = true
            }
        }
    }

    override fun start() {
    }

    /**
     * OnClickListener
     */
    private val onClickListener = View.OnClickListener { view ->
        when (view.id) {
            R.id.btn_save -> {
                updateIsExplicit()
            }
        }
    }
    private fun updateIsExplicit() {
        if (validate()) {
            mPresenter?.updateIsExplicit(pf_uuid,mIsExplicit)
        }
    }
    /**
     * check data
     */
    private fun validate(): Boolean {
        var valid = true
        return valid
    }
}